<?php
/**
 * Created by PhpStorm.
 * User: sosyuki
 * Date: 2018-11-24
 * Time: 16:06
 */

namespace Drupal\points\ViewsController;


use Drupal\points\ViewsController\handler\field\PointsEditLink;
use Drupal\points\ViewsController\handler\field\PointsPointViewsField;
use Drupal\points\ViewsController\handler\field\PointsTotalViewsField;
use Drupal\points\ViewsController\handler\field\total_calculate;
use EntityDefaultViewsController;

class PointsViewsController extends EntityDefaultViewsController {

  function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $data[$table]['total_calculate'] = [
        'title' => t('积分总（可计算）'),
        'help' => t('积分总（可计算）.'),
        'real field' => 'point',
        'field' => [
          'handler' => total_calculate::class,
        ],
      ];

      $data[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => PointsEditLink::class,
        ],
      ];

      $info = [];
      $info[$table]['point'] = [
        'title' => '单次积分获取数量',
        'help' => '单次积分获取数量',
        'real field' => 'point',
        'field' => [
          'handler' => PointsPointViewsField::class,
        ],
      ];
      $info[$table]['total'] = [
        'title' => '历史结余',
        'help' => '历史结余',
        'real field' => 'total',
        'field' => [
          'handler' => PointsTotalViewsField::class,
        ],
      ];
      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
